package approve.action;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ApporoveNewActivity extends Activity {
	String database = "admin";
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	String lang = "EN";
	ListView list;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu_newdocument);
        loadList();
        list.setOnItemClickListener(selectItem);
	}
	 public String getLang() {
			Bundle extras = getIntent().getExtras();
			if (extras != null) {
				lang = extras.getString("lang");
			}
			return lang;
		}
	    public void loadList(){
	    	ArrayAdapter<String> listType = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listAll(getLang()));
	    	list = (ListView)findViewById(R.id.listTypeDoc);
	    	list.setAdapter(listType);
	    }
	    public String[] listAll(String value){
	    	String[] menu = null;
			if(value.equals("EN")){
				menu = getResources().getStringArray(R.array.newdocument_en);
			}else if(value.equals("KR")){
				menu = getResources().getStringArray(R.array.newdocument_kr);
			}else {
				menu = getResources().getStringArray(R.array.newdocument_vn);
			}
			return menu;
	    }
//	    public ArrayList<String> listAll(){
//	    	ListDocuments call = new ListDocuments();
//	    	ArrayList<String> list = call.getTypeDoc(getLang());
//	    	ArrayList<Typedoc> arr = call.getAllType(getLang());
//	    	for(int i=0;i<arr.size();i++){
//	    		list.add(arr.get(i).getTypeName());
//	    	}
//	    	return call.getTypeDoc(getLang());
//	    }
	    private OnItemClickListener selectItem = new OnItemClickListener() {
	    	public void onItemClick(android.widget.AdapterView<?> arg0, android.view.View arg1, int arg2, long arg3) {
	    		String item = arg0.getItemAtPosition(arg2).toString();
				if(item.equals("Metting Form") || item.equals("회의양식") || item.equals("Văn Bản Hội Họp")){
					Intent myIntent = new Intent(ApporoveNewActivity.this,SendDocActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", getDatabase());
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Document Work report") || item.equals("출장 신청서") || item.equals("Báo cáo công tác")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, WorkReportActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Daily Report") || item.equals("일일업무보고서") || item.equals("Báo cáo công việc")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, DailyReportActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Weekly Report Document") || item.equals("주간보고") || item.equals("Báo cáo hàng tuần")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, WeeklyReportActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Purchase Order Form") || item.equals("구매 요청서") || item.equals("Mẫu Mua Hàng")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, PurchaseOrderForm.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
	    	};
		};
}
